import { request as umiRequest } from 'umi';
import { RequestConfig } from '@@/plugin-request/request';
import { AppResult } from '@/types/base-type';

const isDevelopmentEnvironment = () => {
  try {
    // @ts-ignore define for .umirc.ts
    return active === 'dev';
  } catch (e) {
    return false;
  }
};

const request = (url: string, options?: RequestConfig) => {
  return umiRequest(isDevelopmentEnvironment() ? ('/api' + url) : url, {
    ... options,
  });
};

const isResponseSuccess = (response?: AppResult<any>): boolean => {
  return response?.code === '200';
};


export { request, isResponseSuccess, isDevelopmentEnvironment };
